/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View.venta;

import Controller.MovimientoC;
import Model.MovimientoM;
import Util.ArrayListTableModel;
import java.util.ArrayList;
import java.util.List;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author Maryluz
 */
public class frmListaPrendas extends javax.swing.JDialog {

    /**
     * Creates new form frmListaPrendas
     */
    public frmListaPrendas(java.awt.Frame parent, boolean modal, int tienda, String nomtienda) {
        super(parent, modal);
        initComponents();
        configurarTabla();
        txtTienda.setText(nomtienda.toUpperCase());
        cargarTabla(tienda);
        this.setResizable(false);
        this.setLocationRelativeTo(null); 
        tbnLista.setRowHeight(45);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tbnLista = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        txtTienda = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Lista de Prendas");

        tbnLista.setFont(new java.awt.Font("Calibri", 0, 16)); // NOI18N
        tbnLista.setModel(new ArrayListTableModel(
            new Object [][] {},
            new String [] {"     #"," DESCRIPCIÓN","    STOCK","    PRECIO",""}
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false,false,false,false,false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tbnLista);

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel7.setFont(new java.awt.Font("Calibri", 1, 24)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 204, 51));
        jLabel7.setText("PRENDAS POR TIENDA");

        txtTienda.setFont(new java.awt.Font("Calibri", 1, 20)); // NOI18N
        txtTienda.setForeground(new java.awt.Color(255, 255, 255));
        txtTienda.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(124, 124, 124)
                .addComponent(jLabel7)
                .addContainerGap(139, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txtTienda, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(txtTienda, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbnLista;
    private javax.swing.JLabel txtTienda;
    // End of variables declaration//GEN-END:variables

    private void cargarTabla(int tienda) {

        switch (tienda) {
            case 1:
                cargarTaller();
                break;
            case 2:
                cargarTienda(2);
                break;
            case 3:
                cargarTienda(3);
                break;

        }
    }

    private void cargarTaller() {
        MovimientoC oC = new MovimientoC();
        List<MovimientoM> oMs = oC.listarPrendasTaller();
        @SuppressWarnings("LocalVariableHidesMemberVariable")
        ArrayList oList;
        // limpiarTablaEmisor();
        if (oMs != null) {
            int size = oMs.size();
            for (int a = 0; a < size; a++) {
                oList = new ArrayList();
                oList.add(a + 1);
                oList.add(" " + oMs.get(a).getNombrePrenda());
                oList.add(oMs.get(a).getCantidad());
                oList.add(oMs.get(a).getPrecio());
                oList.add(oMs.get(a));
                ((ArrayListTableModel) tbnLista.getModel()).addRow(oList);
            }
        }
    }

    private void cargarTienda(int x) {
        MovimientoC oC = new MovimientoC();
        List<MovimientoM> oMs = oC.listarPrendasTienda(x);
        ArrayList oList;
        //limpiarTablaEmisor();
        if (oMs != null) {
            int size = oMs.size();
            for (int a = 0; a < size; a++) {
                oList = new ArrayList();
                oList.add(a + 1);
                oList.add(" " + oMs.get(a).getNombrePrenda());
                oList.add(oMs.get(a).getCantidad());
                oList.add(oMs.get(a).getPrecio());
                oList.add(oMs.get(a));
                ((ArrayListTableModel) tbnLista.getModel()).addRow(oList);
            }
        }
    }

    private void configurarTabla() {
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
        tcr.setHorizontalAlignment(SwingConstants.CENTER);

        tbnLista.getColumnModel().getColumn(0).setCellRenderer(tcr);
        tbnLista.getColumnModel().getColumn(2).setCellRenderer(tcr);
        tbnLista.getColumnModel().getColumn(3).setCellRenderer(tcr);
        tbnLista.getColumnModel().getColumn(4).setCellRenderer(tcr);

        tbnLista.getColumnModel().getColumn(0).setMinWidth(50);
        tbnLista.getColumnModel().getColumn(0).setPreferredWidth(50);
        tbnLista.getColumnModel().getColumn(0).setMaxWidth(50);
        tbnLista.getColumnModel().getColumn(2).setMinWidth(70);
        tbnLista.getColumnModel().getColumn(2).setPreferredWidth(70);
        tbnLista.getColumnModel().getColumn(2).setMaxWidth(70);
        tbnLista.getColumnModel().getColumn(3).setMinWidth(70);
        tbnLista.getColumnModel().getColumn(3).setPreferredWidth(70);
        tbnLista.getColumnModel().getColumn(3).setMaxWidth(70);
        tbnLista.getColumnModel().getColumn(4).setMinWidth(0);
        tbnLista.getColumnModel().getColumn(4).setPreferredWidth(0);
        tbnLista.getColumnModel().getColumn(4).setMaxWidth(0);
    }
}
